<?php
header ( 'content-type:text/html; charset=utf-8' );

session_start();

@$userid = $_SESSION['userid'];

if (empty($userid)){
	die(json_encode(array('status'=>false,'info'=>'tips：操作超时　请重新登录')));
}

@$incash = $_REQUEST['money'];

if (empty($incash)){
	die(json_encode(array('status'=>false,'info'=>'tips：存款金额不能为空　难道你想空手套白狼？')));
}

if (!is_numeric($incash)){
	die(json_encode(array('status'=>false,'info'=>'tips：存款金额只能为数字　难道你输入“老婆” 还能存入“老婆”不成？')));
}

if ($incash<0){
	die(json_encode(array('status'=>false,'info'=>'tips：存款金额不能为负数　难道你是想取钱？')));
}

require 'lib/db.php';

@$flag = dbupdate('update user set money=money+:incash where id=:id',array('incash'=>$incash,'id'=>$userid));

if (!$flag){
	die(json_encode(array('status'=>false,'info'=>'tips：存款失败')));
}

@$user = dbselect('select money from user where id=:id',array('id'=>$userid));

echo json_encode(array('status'=>true,'money'=>$user['money']));